package edu.com.wjt219971332.dao;

import edu.com.wjt219971332.entity.Singer;
import edu.com.wjt219971332.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface SingerDao {
    @Select("SELECT * FROM singer WHERE singerid = #{singerid}")
    Singer queryById(Integer singerid);

    @Select("SELECT * FROM singer LIMIT #{pageable.offset}, #{pageable.pageSize}")
    List<Singer> queryAllByLimit(Singer singer, @Param("pageable") Pageable pageable);

    @Select(" select count(1) from singer")
    long count(Singer singer);

    @Insert("INSERT INTO singer (name, age, sex, phone, motto, singerinfo, pic, registertime) VALUES (#{name} ,#{age}, #{sex}, #{phone}, #{motto}, #{singerinfo}, #{pic}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "singerid")
    int insert(Singer singer);


    int insertBatch(@Param("entities") List<Singer> entities);


    int insertOrUpdateBatch(@Param("entities") List<Singer> entities);

    @Update("UPDATE singer SET name = #{name}, age = #{age},sex = #{sex}, phone = #{phone}, motto = #{motto}, singerinfo = #{singerinfo}, pic = #{pic} WHERE singerid = #{singerid}")
    int update(Singer singer);

    @Delete("DELETE FROM singer WHERE singerid = #{singerid}")
    int deleteById(Integer singerid);

    @Select("SELECT * FROM singer WHERE name LIKE CONCAT('%', #{name}, '%')")
    List<Singer> queryByusername(String name);
    @Select("SELECT * FROM singer WHERE name = #{asinger}")
    Singer queryBysingername(String asinger);
}

